<script setup lang="ts">
import OrderItem from "@/components/mine/OrderItem.vue"
import { useRouter } from "vue-router"
import { ref, computed } from "vue"
import { useCounterStore } from "@/stores/counter"
import { storeToRefs } from "pinia"
const router = useRouter();
const active = ref(0);

const store = useCounterStore();
const { orderList } = storeToRefs(store);
const showList = computed(() => {
  let list = [];
  if (active.value == 0) {
    list = orderList.value;
  } else {
    list = orderList.value.filter(el => el.orderStatus == active.value);
  }
  return list;
})
</script>
<template>
  <div class="fixed-zbest order-detail">
    <header class="header">
      <van-icon class="header-icon" name="arrow-left" @click.stop="router.go(-1)" />
      <div class="header-text">订单详情</div>
    </header>
    <div class="nav">
      <div class="nav-item" :class="{ active: active == 0 }" @click.stop="active = 0">全部</div>
      <div class="nav-item" :class="{ active: active == 1 }" @click.stop="active = 1">待付款</div>
      <div class="nav-item" :class="{ active: active == 2 }" @click.stop="active = 2">待收货</div>
      <div class="nav-item" :class="{ active: active == 3 }" @click.stop="active = 3">已完成</div>
    </div>
    <div class="content">
      <div class="content-item" v-if="active == 0">
        <div v-if="showList?.length">
          <OrderItem v-for="(item, index) in showList" :key="index" :item="item" />
        </div>
        <div class="nothing" v-else>
          <div class="img-box animate__animated animate__bounceInDown animate__slow">
            <img src="@/assets/images/shopcart/1678328261551.png" alt="">
          </div>
          <div class="nothing-text animate__animated animate__bounceInRight animate__slow">暂无数据</div>
          <div class="nothing-btn animate__animated animate__bounceInLeft animate__slow"
            @click.stop="router.push('/home')">去逛逛</div>
        </div>
      </div>
      <div class="content-item" v-if="active == 1">
        <div v-if="showList?.length">
          <OrderItem v-for="(item, index) in showList" :key="index" :item="item" />
        </div>
        <div class="nothing" v-else>
          <div class="img-box animate__animated animate__bounceInDown animate__slow">
            <img src="@/assets/images/shopcart/1678328261551.png" alt="">
          </div>
          <div class="nothing-text animate__animated animate__bounceInRight animate__slow">暂无数据</div>
          <div class="nothing-btn animate__animated animate__bounceInLeft animate__slow"
            @click.stop="router.push('/home')">去逛逛</div>
        </div>
      </div>
      <div class="content-item" v-if="active == 2">
        <div v-if="showList?.length">
          <OrderItem v-for="(item, index) in showList" :key="index" :item="item" />
        </div>
        <div class="nothing" v-else>
          <div class="img-box animate__animated animate__bounceInDown animate__slow">
            <img src="@/assets/images/shopcart/1678328261551.png" alt="">
          </div>
          <div class="nothing-text animate__animated animate__bounceInRight animate__slow">暂无数据</div>
          <div class="nothing-btn animate__animated animate__bounceInLeft animate__slow"
            @click.stop="router.push('/home')">去逛逛</div>
        </div>
      </div>
      <div class="content-item" v-if="active == 3">
        <div v-if="showList?.length">
          <OrderItem v-for="(item, index) in showList" :key="index" :item="item" />
        </div>
        <div class="nothing" v-else>
          <div class="img-box animate__animated animate__bounceInDown animate__slow">
            <img src="@/assets/images/shopcart/1678328261551.png" alt="">
          </div>
          <div class="nothing-text animate__animated animate__bounceInRight animate__slow">暂无数据</div>
          <div class="nothing-btn animate__animated animate__bounceInLeft animate__slow"
            @click.stop="router.push('/home')">去逛逛</div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.order-detail {
  width: 100%;
  overflow: scroll;
  background-color: var(--bgc-gray);

  &::-webkit-scrollbar {
    display: none;
  }

  >div {
    background-color: var(--bgc-white);
  }

  .header {
    position: sticky;
    left: 0;
    top: 0;
    z-index: 10;
    width: 100%;
    height: .5rem;
    box-sizing: border-box;
    font-size: .2rem;
    line-height: .5rem;
    padding: 0 .15rem;
    display: flex;
    align-items: center;
    background-color: var(--bgc-white);

    .header-icon {
      font-size: .15rem;
    }

    .header-text {
      flex-grow: 1;
      font-size: .18rem;
      text-align: center;
    }
  }

  .nav {
    width: 100%;
    height: .5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: .14rem;

    .nav-item {
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: center;
      transition: .3s;
    }

    .active {
      color: var(--text-red);
    }
  }

  .content {
    margin-top: .05rem;
    background-color: var(--bgc-gray);

    .nothing {
      width: 100%;
      box-sizing: border-box;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      padding-top: .8rem;

      .img-box {
        width: .9rem;
        height: .9rem;
      }

      .nothing-text {
        margin-top: .3rem;
        margin-bottom: .2rem;
        color: var(--text-gray2);
        opacity: .6;
      }

      .nothing-btn {
        position: relative;
        width: 1.2rem;
        height: .44rem;
        background-color: var(--bgc-red-deep);
        background-image: linear-gradient(to right, var(--bgc-red), var(--bgc-red-deep), var(--bgc-red));
        color: var(--text-white);
        font-size: .16rem;
        border-radius: .04rem;
        line-height: .44rem;
        text-align: center;
      }
    }
  }
}
</style>